package com.etymgiko.spaceshipshop.service.impl;

import com.etymgiko.spaceshipshop.service.UserManager;
import com.etymgiko.spaceshipshop.model.User;
import com.etymgiko.spaceshipshop.dao.UserDao;
import com.etymgiko.spaceshipshop.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;

/**
 * Manages User.
 *
 * @author Ivan Holub
 */
public class UserManagerImpl implements UserManager {

    private PasswordEncoder passwordEncoder;

    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    /**
     * {@inheritDoc} 
     */
    @Transactional(readOnly = true)
    public User getUser(Long userId) {
        return userDao.getUser(userId);
    }

    /**
     * {@inheritDoc}
     */
    @Transactional(readOnly = true)
    public User findUser(String login, String password) {
        String code = passwordEncoder.encodePassword(login, password);
        return userDao.findUser(login, code);
    }
}
